package com.test.notification;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;

import com.persion.sys.R;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

//ellipsis code
// …… .

public class localNotification extends CordovaPlugin {
    @Override
    public boolean execute(String action, final JSONArray args,
                           final CallbackContext callbackContext) throws JSONException {
        if ("sendNotify".equals(action)) {
            NotificationManager manager = (NotificationManager) this.cordova
                    .getActivity().getSystemService(
                            Context.NOTIFICATION_SERVICE);

            String title = args.getString(0);
            String text = args.getString(1);
            Notification notification
                    = new Notification.Builder(this.cordova.getActivity())
                    .setTicker("New notification").setDefaults(1)
                    .setSmallIcon(R.drawable.screen)
                    .setAutoCancel(true)
                    .setContentTitle(title).setContentText(text)
                    .setContentIntent(PendingIntent.getActivity(this.cordova.getActivity(),
                            0, this.cordova.getActivity().getIntent(), 0)).build();
            manager.notify(1, notification);

            return true;
        }
        return false;
    }
}